/**
 * Copyright 2008 Mathias Doenitz, http://lis.to/
 *
 * This file is part of the lis.to java desktop client. The lis.to java desktop client is free software: you can
 * redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * The lis.to java desktop client is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with the lis.to java desktop client.
 * If not, see http://www.gnu.org/licenses/
 */

package listo.client.dialogs.controllers;

import listo.utils.types.Copyable;

import javax.swing.*;
import java.awt.event.FocusListener;

/**
 * Manages the interaction between a model object and a dialog component.
 */
public interface ComponentController<T extends Copyable<T>> extends FocusListener {

    public interface ModelChangedListener {
        /**
         * Called when a controller has changed the model object.
         *
         * @param controllers the controllers the change has been originates from or gone through so far
         */
        public void modelChanged(ComponentController... controllers);
    }

    /**
     * Adds a ModelChangedListener.
     *
     * @param listener the listener
     */
    public void addModelChangedListener(ModelChangedListener listener);

    /**
     * Gets the component this controller is attached to.
     *
     * @return the component
     */
    public JComponent getComponent();

    /**
     * Sets the dialog component the controller is to work with.
     *
     * @param dialog the dialog
     * @param component the component
     */
    public void setDialogComponent(JDialog dialog, JComponent component);

    /**
     * Sets the model object the controller is to work with
     *
     * @param modelObject the model object
     */
    public void setModelObject(T modelObject);

    /**
     *
     * @return true if the component represents a valid model state
     */
    public boolean isComponentValid();
}